import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.ConnectionEvent;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Creater with IntelliJ IDEA.
 * Description:
 * User: 86152
 * Dae: 2022-07-16
 * Time: 11:00
 */
public class JDBCHello {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1/java104?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("760121");

        //建立连接
        Connection connection = dataSource.getConnection();
        System.out.println(connection);

        String sql = "insert into student value(2,'sb')";
        PreparedStatement statement = connection.prepareStatement(sql);

        int n = statement.executeUpdate();
        System.out.println(n);

        statement.close();
        connection.close();
    }
}
